#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

//Definition for a binary tree node.
struct TreeNode {
	int val;
	TreeNode *left;
	TreeNode *right;
	TreeNode() : val(0), left(nullptr), right(nullptr)
	{
	}
	TreeNode(int x) : val(x), left(nullptr), right(nullptr)
	{
	}
	TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right)
	{
	}
};

class Solution {
	tuple<int, int> get_diameter(TreeNode *root)
	{
		if(root == nullptr){
			return {0, 0};
		}
		auto [dr, hr] = get_diameter(root->right);
		auto [dl, hl] = get_diameter(root->left);
		int d = max(dr, dl);
		d = max(d, hr + hl);
		int h = max(hl, hr) + 1;
		return {d, h};
	}
    public:
	int diameterOfBinaryTree(TreeNode *root)
	{
		auto info = get_diameter(root);
		return get<0>(info);
	}
};

TreeNode* create_tree(int p, vector<int> &path)
{
	if(p >= path.size()){
		return nullptr;
	}
	TreeNode *left = create_tree(((p + 1) << 1) - 1, path);
	TreeNode *right = create_tree((p + 1) << 1, path);
	
	return new TreeNode(path[p], left, right);
}

int main()
{
	vector<int> root = {1,2,3,4,5};
	TreeNode *t = create_tree(0, root);
	return 0;
}